package com.augmentum.oes.dao.mybatis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augmentum.oes.dao.BaseDao;
import com.augmentum.oes.dao.ExamDao;
import com.augmentum.oes.model.Exam;
import com.augmentum.oes.model.Pagination;
import com.augmentum.oes.model.Question;
import com.augmentum.oes.util.StringUtil;

import org.springframework.stereotype.Repository;
@Repository
public class ExamDaoImpl extends BaseDao implements ExamDao {
    private final static String PREFIX= Exam.class.getName() + ".";

    @Override
    public int addExam(Exam exam) {
        sst.insert(PREFIX + "saveExam", exam);
        return exam.getId();
    }

    @Override
    public List<Exam> queryExam() {
        return sst.selectList(PREFIX + "allExam");
    }

    @Override
    public Exam findById(int id) {
        return sst.selectOne(PREFIX + "findById", id);
    }

    @Override
    public void update(Exam exam) {
        
    }

    @Override
    public void setConnection(int id1, int id2) {
        Map<String, Object> params = new HashMap<>();
        params.put("id1", id1);
        params.put("id2", id2);
        sst.insert(PREFIX + "setConnection", params);
    }

    @Override
    public void setToBak(Question question) {
        sst.insert(PREFIX + "setToBak", question);
    }

    @Override
    public List<Exam> examPage(Pagination<Exam> page) {
        String fuzzyWord = page.getFuzzyWord();
        page.setFuzzyTrans(StringUtil.shift(fuzzyWord));
        return sst.selectList(PREFIX + "examPage", page);
    }

    @Override
    public int getExamCount(String fuzzyTrans) {
        return sst.selectOne(PREFIX + "getExamCount", fuzzyTrans);
    }

}
